package com.winderinfo.yikaotianxia.ui.record;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.winderinfo.yikaotianxia.R;

import java.util.List;

public class RecordAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<RecordBean.RowsBean> list;

    public RecordAdapter(Context context, List<RecordBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_practicerecords, viewGroup, false);
        SelectedViewHolder selectedViewHolder = new SelectedViewHolder(view);
        return selectedViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
        SelectedViewHolder selectedViewHolder = (SelectedViewHolder) viewHolder;
        selectedViewHolder.p_fen.setText(list.get(i).getScore());
        selectedViewHolder.pa_title.setText(list.get(i).getYkRealTitle().getTitle());
        selectedViewHolder.p_day.setText(list.get(i).getCreatetime());
        selectedViewHolder.p_ti.setText("答题 : " + list.get(i).getComplete() + "道/" + list.get(i).getRemarks() + "道");
        selectedViewHolder.p_time.setText("用时 : " + list.get(i).getTime());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class SelectedViewHolder extends RecyclerView.ViewHolder {

        private final TextView p_day, pa_title, p_ti, p_time, p_fen;


        public SelectedViewHolder(@NonNull View itemView) {
            super(itemView);
            p_day = itemView.findViewById(R.id.p_day);
            pa_title = itemView.findViewById(R.id.pa_title);
            p_ti = itemView.findViewById(R.id.p_ti);
            p_time = itemView.findViewById(R.id.p_time);
            p_fen = itemView.findViewById(R.id.p_fen);
        }
    }


}
